package cn.edu.ctbu.scoremg.controller;


import cn.edu.ctbu.scoremg.entity.User;

import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {

    @RequestMapping("/login")
    public String login(){

        return "/login";
    }
}

//@Controller
//public class LoginController {
//
//    @Autowired
//    private UserService  userService;
//
//    @PostMapping("/login")
//    @ResponseBody
//    public CommonResult<String> login(
//            @RequestParam String username,
//            @RequestParam String password,
//            HttpSession session) throws Exception {
//
//        // 1. 验证用户
//        User user = userService.login(username, password);
//        if (user == null) {
//            return CommonResult.failed("用户名或密码错误");
//        }
//
//        // 2. 存储会话信息
//        session.setAttribute("currentUser", user);
//
//        // 3. 根据角色返回不同跳转路径
//        String redirectUrl = "/";
//        switch (user.getRoleType()) {
//            case 1: redirectUrl = "/admin/dashboard"; break; // 管理员
//            case 2: redirectUrl = "/teacher/courses"; break; // 教师
//            case 3: redirectUrl = "/student/grades"; break;  // 学生
//        }
//
//        return CommonResult.success(redirectUrl);
//    }
//}
